#!/bin/bash

set -e
set -x

cp cluster.xml.tpl cluster.xml

iplist_path=config
i=1
while read -r line
do
    case $line in
        *'#'*)
            continue
        ;;
        *'end'*)
            break
        ;;
        *)
            IFS=',' read -ra parts <<< "$line"
        ;;
    esac
    
    pass="${parts[0]}" 
    address="${parts[1]}"
    hostname="${parts[2]}"
    if [ $address ];then
        sed -i "s/(host$i)/$hostname/g" cluster.xml
        let i=i+1
    fi
done < $iplist_path

set +x
set +e